home *** CD-ROM | disk | FTP | other *** search
- /*
- * messages.c - help with formatting and display of messages
- */
- #include "RevRdist.h"
- #include "TransSkelProto.h"
- #include "TransDisplayProto.h"
- #include <stdarg.h>
-
- extern StringPtr syserrlist (OSErr);
-
-
- /*
- *=========================================================================
- * dispIndStr (w, idx, str, p0, p1, p2, p3) - display STR# with params
- * entry: w = TransDisplay window to display text in
- * idx = string index in STR# resource
- * str = STR# resource id
- * p0, p1, p2, p3 = strings to substitute into text, if fewer
- * than 4 strings are needed, end list early with nil
- *=========================================================================
- */
-
- void
- dispIndStr (
- WindowPtr w,
- Integer idx,
- Integer str,
- StringPtr p0,
- ...)
- {
- Handle h;
- WindowPtr oldw;
- Longint offset;
- Size len;
- va_list ap;
- StringPtr p1, p2, p3;
-
- if (w == nil)
- return;
- h = NewHandle ((Size) 256);
- if (h == nil)
- return;
- p1 = nil; p2 = nil;
- va_start(ap, p0);
- if (p0)
- p1 = va_arg(ap, StringPtr);
- if (p1)
- p2 = va_arg(ap, StringPtr);
- if (p2)
- p3 = va_arg(ap, StringPtr);
- va_end(ap);
- GetDWindow (&oldw); /* remember current window */
- if (w != oldw)
- SetDWindow (w); /* and switch to new window */
- HLock (h);
- GetIndString ((StringPtr) (*h), str, idx);
- if (**h == 0)
- goto eexit;
- HUnlock (h);
- SetHandleSize (h, (Size) (**h) + 1);
- /*
- * For each parameter up to a nil ptr, use Munger to insert it in
- * the text.
- */
- offset = 1;
- if (!p0)
- goto done;
- offset = Munger (h, offset, (Ptr) "^0", 2, &p0[1], (long) p0[0]);
- if (offset < 0)
- goto done;
- if (!p1)
- goto done;
- offset = Munger (h, offset, (Ptr) "^1", 2, &p1[1], (long) p1[0]);
- if (offset < 0)
- goto done;
- if (!p2)
- goto done;
- offset = Munger (h, offset, (Ptr) "^2", 2, &p2[1], (long) p2[0]);
- if (offset < 0)
- goto done;
- if (!p3)
- goto done;
- offset = Munger (h, offset, (Ptr) "^3", 2, &p3[1], (long) p3[0]);
-
- done:
- HLock (h);
- if (w == ActivityWind && Depth > 0)
- DisplayText(" ", (Longint)(Depth <= 10 ? Depth : 10));
- len = GetHandleSize (h) - 1;
- DisplayText ((*h)+1, len);
- DisplayLn ();
- if (w == ActivityWind)
- {
- if (len > 255)
- len = 255;
- **h = len;
- statMsg (*(StringHandle)h);
- }
- eexit:
- HUnlock (h);
- DisposHandle (h);
- if (w != oldw)
- SetDWindow (oldw);
- }
-
-
- /*
- *=========================================================================
- * notice (idx, p0, p1, p2, p3) - write msg to activity window
- * entry: idx = index (L_xxx) of message text
- * p0, ... = strings to substitute in text
- *=========================================================================
- */
- void
- notice (enum activity_e idx, StringPtr p0, ...)
- {
- int i;
- StringPtr ap0, ap1, ap2, ap3;
- unsigned char cbuf[20];
- va_list ap;
-
- va_start(ap, p0);
- i = 0;
- if (ap0 = p0) {
- i = 1;
- ap1 = va_arg(ap, StringPtr);
- if (ap1) {
- i = 2;
- ap2 = va_arg(ap, StringPtr);
- if (ap2) {
- i = 3;
- ap3 = va_arg(ap, StringPtr);
- if (ap3)
- i = 4;
- }
- }
- }
- va_end(ap);
- switch (i)
- {
- case 0: ap0 = Clue0;
- case 1: ap1 = Clue1;
- case 2: ap2 = (idx == L_SYS || idx == L_FILE) ? syserrlist(ClueID) : Clue2;
- case 3: ap3 = Clue3;
- }
- dispIndStr (ActivityWind, idx, LST_STR, ap0, ap1, ap2, ap3);
- }
-
-
- /*
- *=========================================================================
- * panic (f, idx, p0, p1, p2) - display panic alert
- * entry: f = false if user can choose to ignore error
- * idx = index in ERR_STR of text
- * p0, p1, p2 = substitutable text
- * exit: Quit set true if user selects CANCEL
- *=========================================================================
- */
-
- void
- panic (Boolean f, enum error_e idx, StringPtr p0, ...)
- {
- Integer i;
- Integer oldresfile;
- StringPtr ap0, ap1, ap2;
- Str255 buf;
- unsigned char cbuf[20];
- va_list ap;
-
- va_start(ap, p0);
- i = 0;
- if (ap0 = p0) {
- i = 1;
- ap1 = va_arg(ap, StringPtr);
- if (ap1) {
- i = 2;
- ap2 = va_arg(ap, StringPtr);
- if (ap2)
- i = 3;
- }
- }
- va_end(ap);
- switch (i)
- {
- case 0: ap0 = Clue0;
- case 1: ap1 = Clue1;
- case 2: ap2 = (idx == E_SYS || idx == E_FILE) ? syserrlist(ClueID) : Clue2;
- }
- oldresfile = CurResFile ();
- UseResFile (Ap_refNum);
- GetIndString (buf, ERR_STR, idx);
- ParamText (ap0, ap1, ap2, buf);
- if (f)
- i = StopAlert (RSRC_BASE+ALERT_PANIC, nil);
- else
- i = CautionAlert (RSRC_BASE+ALERT_WARN, nil);
- if (f || i == ALRT_CANCEL)
- Quit = true;
- UseResFile (oldresfile);
- }
-
- /*
- *=========================================================================
- * warning (idx, p0, p1, p2, p3) - display warning message
- * in the error and activity windows
- * and produce an alert unless we are the startup application
- * entry: idx = index in ERR_STR STR# of text
- * p0, p1, p2 = substitutable text
- *=========================================================================
- */
-
- void
- warning (enum error_e idx, StringPtr p0, ...)
- {
- Integer i;
- static oldidx = -1;
- Integer oldresfile;
- StringPtr ap0, ap1, ap2, ap3;
- Str255 buf;
- unsigned char cbuf[20];
- va_list ap;
-
- va_start(ap, p0);
- i = 0;
- if (ap0 = p0) {
- i = 1;
- ap1 = va_arg(ap, StringPtr);
- if (ap1) {
- i = 2;
- ap2 = va_arg(ap, StringPtr);
- if (ap2)
- i = 3;
- }
- }
- va_end(ap);
- switch (i)
- {
- case 0: ap0 = Clue0;
- case 1: ap1 = Clue1;
- case 2: ap2 = (idx == E_SYS || idx == E_FILE) ? syserrlist(ClueID) : Clue2;
- }
- oldresfile = CurResFile ();
- UseResFile (Ap_refNum);
- dispIndStr (ActivityWind, idx, ERR_STR, ap0, ap1, ap2, nil);
- dispIndStr (ErrorWind, idx, ERR_STR, ap0, ap1, ap2, nil);
- ErrorMsgs++;
- if (idx == E_DOQUIT || (!(Flags & PF_STARTUP) && idx != oldidx) )
- {
- GetIndString (buf, ERR_STR, idx);
- ParamText (ap0, ap1, ap2, buf);
- i = CautionAlert (RSRC_BASE+ALERT_WARN, nil);
- if (i == ALRT_CANCEL)
- Quit = true;
- }
- if (Flags & PF_STARTUP)
- Quit = true;
- oldidx = idx;
- UseResFile (oldresfile);
- }